package logic

import (
	"context"
	"pinduoduo/models"
	"pinduoduo/pkg"
	"time"

	"pinduoduo/userrpc/internal/svc"
	"pinduoduo/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *userrpc.SendSmsRequest) (*userrpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	rand := pkg.Rand()
	//resp, err := pkg.SendSms(in.Mobile, rand)
	//if err != nil {
	//	return nil, fmt.Errorf(err.Error())
	//}
	//if *resp.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*resp.Body.Message)
	//}

	models.Rdb.Set("sendSms"+in.Source+in.Mobile, rand, time.Minute*5)
	return &userrpc.SendSmsResponse{}, nil
}
